﻿using Fake_Shop_WebApi.Dtos;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace Fake_Shop_WebApi.ValidationAttributes
{
    /// <summary>
    /// 用于数据校验
    /// </summary>
    public class TouristRouteTitleMustBeDifferentFromDescriptionAttribute : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            //获取需要校验的对象
            var TouristRoute = (TouristRouteForManipulationDto)validationContext.ObjectInstance;
            if (TouristRoute.Title == TouristRoute.Description)
            {
                return new ValidationResult("输入的旅游路线的值不能一样", new[] { "TouristRouteForCartionDto" });
            }
            return ValidationResult.Success;
        }
    }
}
